package com.flca.frw.validators;

import java.util.ArrayList;
import java.util.List;

public class ValidateException extends Exception {

	private static final long serialVersionUID = 5800986664242704023L;

	private List<ValidationError> validationErrors;
	
	public ValidateException(List<ValidationError> aValidationErrors) {
		validationErrors = aValidationErrors;
	}

	public ValidateException(ValidationError aError) 
	{
		validationErrors = new ArrayList<ValidationError>();
		validationErrors.add(aError);
	}


	@Override
	public String getMessage() 
	{
		StringBuffer sb = new StringBuffer();
		if (validationErrors != null) {
			for (ValidationError err : validationErrors) {
				String s = err.toFormattedMessage();
				sb.append(s + "\n");
			}
		}
		return sb.toString();
	}

	
	public List<ValidationError> getValidationErrors() {
		return validationErrors;
	}

	
	public String toString() {
		return super.toString() + getMessage();
	}
}
